package com.gaohe.web.controller.dcp;

import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.core.domain.entity.SysUser;
import com.gaohe.system.domain.vo.AuthAboutVo;
import com.gaohe.system.service.IAuthAboutService;
import com.gaohe.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/authAbout")
public class AuthAboutController extends BaseController {

  @Autowired private ISysUserService userService;
  @Autowired private IAuthAboutService authAboutService;

  /**
   * 根据用户编号获取关联病患
   */
  @GetMapping("/{userId}")
  public AjaxResult authAbout(@RequestParam("userId") Long userId) {
    System.out.println(userId);// 使用 @RequestParam
    System.out.println(111);
    AjaxResult ajax = AjaxResult.success();
    SysUser user = userService.selectUserById(userId);
    List<AuthAboutVo> about = authAboutService.selectPatientsByUserId(userId);
    System.err.println(about);
    ajax.put("user", user);
    ajax.put("about", about);
    return ajax;
  }

  /**
   * 修改量表获取信息
   */
  @GetMapping("/patient/{patientId}")
  public AjaxResult authAbout1(@PathVariable("patientId") Long patientId) {
    AjaxResult ajax = AjaxResult.success();
    List<AuthAboutVo> about = authAboutService.selectPatientsBypatientId(patientId);
    System.err.println(about);
    ajax.put("about", about);
    return ajax;
  }

  /**
   * 保存修改量表
   */
  @PostMapping
  public AjaxResult updateAuthAbout(@RequestBody AuthAboutVo authAboutVo) {
    return toAjax(authAboutService.updateStatus(authAboutVo));
  }
}